package com.sc.design.observable;

import java.util.ArrayList;

/**
 * @author sc
 * Created on  2017/12/6
 */
public class Hanfeizi implements Observable,IHanfeizi {
    private ArrayList<Observer> observers = new ArrayList<>();
    @Override
    public void eat() {
        System.out.println("韩非子吃饭");
        this.notifyObservers("他在吃饭");
    }

    @Override
    public void haveFun() {
        System.out.println("韩非子休息");
        this.notifyObservers("他休息了");
    }

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void delObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String context) {
        for(Observer observer:observers){
            observer.update(context);
        }
    }
}
